package com.smartscreen.contentmanage.controller;

import com.smartscreen.contentmanage.service.ClassMomentService;
import com.smartscreen.common.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/content/moments")
@Validated
public class MomentApprovalController {
    
    @Autowired
    private ClassMomentService classMomentService;
    
    /**
     * 审核班级动态
     * @param momentId 动态ID
     * @param request 审核请求
     * @return 审核结果
     */
    @PostMapping("/{momentId}/approval")
    public ApiResponse<Void> approveMoment(
            @PathVariable String momentId,
            @RequestBody Map<String, String> request) {
        
        try {
            if (momentId == null || momentId.trim().isEmpty()) {
                return ApiResponse.badRequest("动态ID不能为空");
            }
            
            String status = request.get("status");
            if (status == null || status.trim().isEmpty()) {
                return ApiResponse.badRequest("审核状态不能为空");
            }
            
            String reason = request.get("reason");
            
            boolean success = classMomentService.approveMoment(momentId, status, reason);
            
            if (success) {
                return ApiResponse.success("审核操作成功");
            } else {
                return ApiResponse.serverError("审核操作失败");
            }
        } catch (Exception e) {
            return ApiResponse.serverError("审核操作失败：" + e.getMessage());
        }
    }
}